/**
 * jims
 */
package com.jims.master.modules.nurse.web;


import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.DateUtils;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.web.impl.BaseDto;
import com.jims.master.modules.doctor.entity.ExamApply;
import com.jims.master.modules.doctor.entity.LabApply;
import com.jims.master.modules.doctor.entity.PatVisit;
import com.jims.master.modules.doctor.entity.PrescriptionApply;
import com.jims.master.modules.doctor.service.ExamApplyService;
import com.jims.master.modules.doctor.service.LabApplyService;
import com.jims.master.modules.doctor.service.PatVisitService;
import com.jims.master.modules.doctor.service.PrescriptionApplyService;
import com.jims.master.modules.drug.service.DrugStorageDeptService;
import com.jims.master.modules.finance.entity.InpBillDetail;
import com.jims.master.modules.finance.service.InpBillDetailService;
import com.jims.master.modules.finance.service.PatPrepaymentService;
import com.jims.master.modules.nurse.entity.BedRec;
import com.jims.master.modules.nurse.service.BedRecService;
import com.jims.master.modules.orders.entity.DrugDispRec;
import com.jims.master.modules.orders.entity.Orders;
import com.jims.master.modules.orders.service.DrugDispMidService;
import com.jims.master.modules.orders.service.DrugDispRecService;
import com.jims.master.modules.orders.service.OrdersService;
import com.jims.master.modules.sys.entity.OrgDept;
import com.jims.master.modules.sys.service.OrgDeptService;
import com.jims.master.modules.sys.utils.UserUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 护士端查询
 */
@Controller
@RequestMapping(value = "${adminPath}/nurse")
public class NurseIndexController extends BaseController {

    @Autowired
    private BedRecService bedRecService;
	@Autowired
	private PatVisitService patVisitService;
	@Autowired
    private OrdersService ordersService;
	@Autowired
	private InpBillDetailService inpBillDetailService;
	@Autowired
	private PatPrepaymentService patPrepaymentService;
	@Autowired
	private PrescriptionApplyService prescriptionApplyService;
	@Autowired
	private ExamApplyService examApplyService;
	@Autowired
	private LabApplyService labApplyService;
	@Autowired
	private OrgDeptService orgDeptService;
	@Autowired
	private DrugDispMidService drugDispMidService;
	@Autowired
	private DrugStorageDeptService drugStorageDeptService;
	@Autowired
	private DrugDispRecService drugDispRecService;

	/**
	 * 床位列表
	 * @param bedRec
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @author 陈涛
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String index(BedRec bedRec,HttpServletRequest request, HttpServletResponse response, Model model) {
        OrgDept orgDept=UserUtils.getUser().getOrgDept();
        if(orgDept!=null){
            String orgDeptId = orgDept.getId();
            bedRec.setOrgId(UserUtils.getOrgId());
            bedRec.setDeptId(orgDeptId);
            bedRec.setWordCode(orgDeptId);
            List<BedRec> list = bedRecService.bedPatientList(bedRec);
            model.addAttribute("list", list);
        }
		return "modules/nurse/nurseIndex";
	}

	/**
	 * 护士执行单
	 * @param visitId
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"performSingle", ""})
	public String performSingle(String visitId,String type,Model model){
		PatVisit patVisit = patVisitService.get(visitId);
 		//List<Orders> orderses = ordersService.performOrders(visitId,type);
		model.addAttribute("patVisit",patVisit);
		//model.addAttribute("orders",orderses);
      return "modules/nurse/performSingleForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = {"performSingleBottom", ""})
	public String performSingleBottom(String visitId,String type,Model model){
		List<Orders> orderses = ordersService.performOrders(visitId,type);
//		model.addAttribute("patVisit",patVisit);
		model.addAttribute("orders",orderses);
		if("treatment".equals(type)){
			return "modules/nurse/preformSingleTable_2";
		}else{
			return "modules/nurse/preformSingleTable_1";
		}
	}

	/**
	 * 执行单打印
	 * @param patVisit,type
	 * @return
	 *@author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"printExeuteReport", ""})
	@ResponseBody
	public StringData printExeuteReport(PatVisit patVisit,String type){
		StringData stringData = new StringData();
		String  printPath =ordersService.printExeuteReport(patVisit,type);
		stringData.setCode("success");
		stringData.setData(printPath);
		return stringData;
	}

	/**
	 * 一日清单查询
	 * @param patVisit
	 * @param model
	 * @author 赵宁
	 * @return
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"dayOfList", ""})
	public String dayOfList(PatVisit patVisit,Model model){
		if(StringUtils.isBlank(patVisit.getStartDate())){
			patVisit.setStartDate(DateUtils.getDate());
		}
		if(StringUtils.isBlank(patVisit.getEndDate())){
			patVisit.setEndDate(DateUtils.getDate());
		}
		String wardCode= UserUtils.getUser().getOrgDept().getId();
		patVisit.setWardCode(wardCode);
		List<PatVisit> list = patVisitService.findList(patVisit);
		model.addAttribute("list",list);
		model.addAttribute("patVisit",patVisit);
		return "modules/nurse/dayOfList";
	}

	/**
	 * 一日清单打印
	 * @param patVisit
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"printBillItems", ""})
	@ResponseBody
	public StringData printBillItems(PatVisit patVisit){
		if(StringUtils.isBlank(patVisit.getStartDate())){
			patVisit.setStartDate(DateUtils.getDate());
		}
		if(StringUtils.isBlank(patVisit.getEndDate())){
			patVisit.setEndDate(DateUtils.getDate());
		}
		String wardCode= UserUtils.getUser().getOrgDept().getId();
		patVisit.setWardCode(wardCode);
		StringData data = new StringData();
		data.setCode("success");
		data.setData(patVisitService.printBillItems(patVisit));
		return data;
	}

	/**
	 * 查询病人收费明细
	 * @param visitId
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"billDetails", ""})
    public String billDetails(String visitId,String startDate,String endDate,Model model){
         List<BaseDto> list= inpBillDetailService.findDetails(visitId,startDate,endDate);
		 model.addAttribute("billDetails",list);
		return "modules/nurse/dayOfListBillDetails";
	}

	/**
	 * 预交金欠费查询
	 * @param name
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"paymentsSearch", ""})
	public String paymentsSearch(String name,Model model,HttpServletRequest request,HttpServletResponse response){
	  String wardCOde= UserUtils.getUser().getOrgDept().getId();
	  String orgId = UserUtils.getOrgId();
      Page<BaseDto> page=patPrepaymentService.getPaymentBlance(new Page<BaseDto>(request,response),wardCOde,orgId,name);
	   model.addAttribute("page",page);
		model.addAttribute("name",name);
       return "modules/nurse/prePaymentSerach";
	}

	/**
	 * 处方查询
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"drugSearch", ""})
	public String drugSearch(Model model,PatVisit patVisit){
        String  wardCode= UserUtils.getUser().getOrgDept().getId();
		patVisit.setWardCode(wardCode);
	    List<PatVisit> patVisits=patVisitService.findList(patVisit);
		model.addAttribute("patVisits",patVisits);
      return "modules/nurse/drugSearch";
	}

	/**
	 * 处方信息查询
	 * @param visitId
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"drugInfoSearch", ""})
	public String drugInfoSearch(String visitId,Model model,HttpServletRequest request ,HttpServletResponse response){
         PatVisit patVisit= patVisitService.get(visitId);
         Page<PrescriptionApply> page = prescriptionApplyService.prescInfoSearch(new Page<PrescriptionApply>(request,response),new PrescriptionApply(),visitId);
		 model.addAttribute("patVisit",patVisit);
		 model.addAttribute("page",page);
		 return "modules/nurse/drugSearchInfo";
	}

	/**
	 * 检查单查询
	 * @param model
	 * @return
	 * @author 赵宁
	 * @update_by CTQ AT 2017-06-26 17:15:11
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"examApply", ""})
	public String examApply(Model model,String startDate,String endDate,ExamApply examApply,HttpServletRequest request,HttpServletResponse response){
      if(startDate==null){
		  startDate=DateUtils.getDate();
	  }
		if(endDate==null ){
			endDate=DateUtils.getDate();
		}
        String billingDept = UserUtils.getUser().getOrgDept().getId();
		examApply.setWardCode(billingDept);
		examApply.setInoroutFlag("1");
		examApply.setStartDate(startDate + " 00:00:00");
		examApply.setEndDate(endDate+" 23:59:59");
		Page<ExamApply> page= examApplyService.findPage(new Page<ExamApply>(request,response),examApply);
		model.addAttribute("page",page);
		model.addAttribute("startDate",startDate);
		model.addAttribute("endDate",endDate);
      return "modules/nurse/examSheet";
	}
	/**
	 * 检查单打印
	 * @param examApply
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"printExamApply", ""})
	@ResponseBody
	public StringData printExamApply(ExamApply examApply){
		StringData stringData = new StringData();
		examApply.setInoroutFlag("1");
		examApply.setStartDate(examApply.getStartDate() + " 00:00:00");
		examApply.setEndDate(examApply.getEndDate()+" 23:59:59");
		String printPath = examApplyService.printExamApply(examApply,UserUtils.getUser());
		stringData.setData(printPath);
		stringData.setCode("success");
		return stringData;
	}

	/**
	 * 检验单查询
	 * @param model
	 * @param startDate
	 * @param endDate
	 * @param labApply
	 * @author 陈涛
	 * @return
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"labApply", ""})
	public String labApply(Model model,String startDate,String endDate,LabApply labApply,HttpServletRequest request,HttpServletResponse response) {
		if(startDate==null){
			startDate=DateUtils.getDate();
		}
		if(endDate==null ){
			endDate=DateUtils.getDate();
		}
		labApply.setStartDate(startDate + " 00:00:00");
		labApply.setEndDate(endDate + " 23:59:59");
		labApply.setInoroutFlag("1");
		String billingDept = UserUtils.getUser().getOrgDept().getId();
		labApply.setWardCode(billingDept);
		Page<LabApply> page = labApplyService.findPage(new Page<LabApply>(request, response), labApply);
		model.addAttribute("page", page);
		model.addAttribute("startDate", startDate);
		model.addAttribute("endDate", endDate);
		return "modules/nurse/labSheet";
	}


	/**
	 * 检验单打印
	 * @param labApply
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"printLabApply", ""})
	@ResponseBody
	public StringData printLabApply(LabApply labApply){
		StringData stringData = new StringData();
		labApply = labApplyService.get(labApply.getId());
		labApply.setInoroutFlag("1");
		labApply.setStartDate(labApply.getStartDate() + " 00:00:00");
		labApply.setEndDate(labApply.getEndDate()+" 23:59:59");
		String printPath = labApplyService.printLabApply(labApply,UserUtils.getUser());
		stringData.setData(printPath);
		stringData.setCode("success");
		return stringData;
	}
    /**
     * 病区工作量查询
     * @param inpBillDetail
     * @return
     * @author 杨富达
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"wardCodeIndex", ""})
    public String wardCodeList(InpBillDetail inpBillDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
        if(inpBillDetail.getStartTime()==null){
            inpBillDetail.setStartTime(DateUtils.getDate());
        }
        if(inpBillDetail.getEndTime()==null ){
            inpBillDetail.setEndTime(DateUtils.getDate());
        }
        model.addAttribute("inpBillDetail", inpBillDetail);
//        inpBillDetail.setStartTime(inpBillDetail.getStartTime() + " 00:00:00");
//        inpBillDetail.setEndTime(inpBillDetail.getEndTime()+" 23:59:59");
        Page<InpBillDetail> page = inpBillDetailService.wardCodeFindPage(new Page<InpBillDetail>(request, response), inpBillDetail);
        //计算并添加费用合计行
        double totalCost = 0D;
        if(page.getList() != null && page.getList().size()>0){
            for(InpBillDetail inpBillDetail1 : page.getList()){
                totalCost += inpBillDetail1.getItemPrice();
            }
        }
        model.addAttribute("totalCost", Double.valueOf(totalCost));
        model.addAttribute("page", page);
        return "modules/finance/wardCodeIndex";
    }
    /**
     * 护理工作量查询
     * @param inpBillDetail
     * @return
     * @author 杨富达
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"wardCodesIndex", ""})
    public String wardCodesList(InpBillDetail inpBillDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
        if(inpBillDetail.getStartTime()==null){
            inpBillDetail.setStartTime(DateUtils.getDate());
        }
        if(inpBillDetail.getEndTime()==null ){
            inpBillDetail.setEndTime(DateUtils.getDate());
        }
        model.addAttribute("inpBillDetail", inpBillDetail);
        /*inpBillDetail.setStartTime(inpBillDetail.getStartTime() + " 00:00:00");
        inpBillDetail.setEndTime(inpBillDetail.getEndTime()+" 23:59:59");*/
        inpBillDetail.setItemClass("K");//设置为护理项目分类
        Page<InpBillDetail> page = inpBillDetailService.wardCodeFindPage(new Page<InpBillDetail>(request, response), inpBillDetail);
        //计算并添加费用合计行
        double totalCost = 0D;
        if(page.getList() != null && page.getList().size()>0){
            for(InpBillDetail inpBillDetail1 : page.getList()){
                totalCost += inpBillDetail1.getItemPrice();
            }
        }
        model.addAttribute("totalCost", totalCost);
        model.addAttribute("page", page);
        return "modules/finance/wardCodesIndex";
    }
	/**
	 * 费医嘱费用查询
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"unOrderBill", ""})
    public String unOrderBill(Model model ,String visitId,HttpServletRequest request,HttpServletResponse response ){

       return "";
	}

    /**
     * 费用查询
     * @param model
     * @param visitId
     * @param request
     * @param response
     * @return String
     * @author 赵宁
     */
    @RequiresPermissions("user")
    @RequestMapping(value = {"searchBill", ""})
    public String searchBill(Model model,String visitId,String patientId,InpBillDetail inpBillDetail,HttpServletRequest request,HttpServletResponse response ){
        if(visitId!=null && visitId!=""){
            inpBillDetail.setVisitId(visitId);
        }
        if(inpBillDetail.getStartTime()==null || "".equals(inpBillDetail.getStartTime())){
            inpBillDetail.setStartTime(DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
        }
        if(inpBillDetail.getEndTime()==null || "".equals(inpBillDetail.getEndTime())){
            inpBillDetail.setEndTime(DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
        }
        inpBillDetail.setOrgId(UserUtils.getOrgId());
        PatVisit patVisit = patVisitService.getPatInfoBill(inpBillDetail);
        patVisit.setPatientId(patientId);
        Page<InpBillDetail> page=inpBillDetailService.findListBy(new Page<InpBillDetail>(request,response),inpBillDetail);
        model.addAttribute("page",page);
        model.addAttribute("patVisit",patVisit);
        model.addAttribute("inpBillDetail",inpBillDetail);
        return "modules/nurse/inpBillSearch";
    }

	/**
	 * 查询费用信息-打印
	 * @param inpBillDetail
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"searchBillPrint", ""})
	@ResponseBody
	public StringData searchBillPrint(InpBillDetail inpBillDetail){
		StringData stringData = new StringData();
		if(inpBillDetail.getStartTime()==null || "".equals(inpBillDetail.getStartTime())){
			inpBillDetail.setStartTime(DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
		}
		if(inpBillDetail.getEndTime()==null || "".equals(inpBillDetail.getEndTime())){
			inpBillDetail.setEndTime(DateUtils.getDate("yyyy-MM-dd HH:mm:ss"));
		}
		inpBillDetail.updateOrgId();
		String printPath=inpBillDetailService.searchBillPrint(inpBillDetail);
		stringData.setCode("success");
		stringData.setData(printPath);
		return stringData;
	}
	/**
	 * 费用核对查询
	 * @param model
	 * @param visitId
	 * @param request
	 * @param response
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"checkCosts", ""})
	public String checkCosts(Model model,String visitId,Orders orders,HttpServletRequest request,HttpServletResponse response){
        orders.setVisitId(visitId);
		PatVisit patVisit=patVisitService.get(visitId);
        Page<Orders> page=ordersService.findOrdersPage(new Page<Orders>(request,response),orders);
		model.addAttribute("page",page);
		model.addAttribute("patVisit",patVisit);
		return "modules/nurse/checkCosts";
	}

	/**
	 * 根据医嘱ID查询收费明细9
	 * @param orderId
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"searchDetailByOrder",""})
	public String searchDetailByOrder(String orderId,Model model,InpBillDetail inpBillDetail,
									  HttpServletRequest request,HttpServletResponse response){
		 inpBillDetail.setOrdersId(orderId);
		 Page<InpBillDetail> page=inpBillDetailService.findPage(new Page<InpBillDetail>(request, response), inpBillDetail);
	     model.addAttribute("inpPage",page);
		 return "modules/nurse/checkCostsDetals";

	}

	/**
	 * 查询病人基本信息
	 * @param visitId
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"patientBasicInfo",""})
	public String patientBasicInfo(String visitId,Model model){
		 PatVisit patVisit=patVisitService.get(visitId);
		 model.addAttribute("patVisit",patVisit);
		 return "modules/nurse/patientBasicInfo";
	}

	/**
	 * 计价单查询
	 * @param visitId
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"denomSign",""})
	public String denomSign(String visitId,InpBillDetail inpBillDetail,HttpServletRequest request,
							HttpServletResponse response,Model model){
		if(inpBillDetail.getStartTime()==null || "".equals(inpBillDetail.getStartTime())){
			inpBillDetail.setStartTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		if(inpBillDetail.getEndTime()==null || "".equals(inpBillDetail.getEndTime())){
			inpBillDetail.setEndTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		if(visitId!=null){
			inpBillDetail.setVisitId(visitId);
		}
		PatVisit patVisit=patVisitService.get(visitId);
		Page<InpBillDetail> page=inpBillDetailService.findPage(new Page<InpBillDetail>(request,response),inpBillDetail);
		model.addAttribute("patVisit",patVisit);
		model.addAttribute("page",page);
		model.addAttribute("inpBillDetail",inpBillDetail);
		return "modules/nurse/denomSign";
	}

	/**
	 * 护理端-计价单-打印
	 * @param inpBillDetail
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"denomSignPrint", ""})
	@ResponseBody
	public StringData denomSignPrint(InpBillDetail inpBillDetail,String name) {
		StringData stringData = new StringData();
		if(inpBillDetail.getStartTime()==null || "".equals(inpBillDetail.getStartTime())){
			inpBillDetail.setStartTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		if(inpBillDetail.getEndTime()==null || "".equals(inpBillDetail.getEndTime())){
			inpBillDetail.setEndTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		String printPath=inpBillDetailService.denomSignPrint(inpBillDetail,name);
		stringData.setCode("success");
		stringData.setData(printPath);
		return stringData;
	}
//	/**
//	 * 摆药查询
//	 * @param orders
//	 * @param request
//	 * @param response
//	 * @param model
//	 * @return
//	 */
//	@RequiresPermissions("user")
//	@RequestMapping(value = {"dispIndex", ""})
//	public String countByDrug(Orders orders, HttpServletRequest request, HttpServletResponse response, Model model) {
//		String wardCode = UserUtils.getUser().getOrgDept().getId();
//
//		//String visitNo = orders.getVisitNo();
//		String storageId = orders.getStorageId();
//		Integer days = orders.getDays();
//		request.getSession(true).removeAttribute("dispOrderDetails");
//		request.getSession(true).setAttribute("dispOrderDetails", "");
//		if (wardCode != null && !"".equals(wardCode)) {
//			OrgDept orgDept=orgDeptService.get(wardCode);
//			orders.setDeptName(orgDept.getDeptName());
//			//查询摆药医嘱
//			List<Orders> dispOrderDetails = this.ordersService.findDispOrders(wardCode, "", storageId, UserUtils.getOrgId(), days,orders.getBedNo());
//			if (dispOrderDetails != null && !dispOrderDetails.isEmpty()) {
//				Map<String, Object> result = drugDispMidService.saveData(dispOrderDetails);
//				Integer rows = (Integer) result.get("rows");
//				String dispNo = (String) result.get("dispNo");
//				if (rows <= dispOrderDetails.size()) {
//					request.getSession(true).setAttribute("dispOrderDetails", dispOrderDetails);
//					orders.setDispNo(dispNo);
//					//按药品分类统计
//					// 1 获取药品数量
//					List<CountDrug> countDrugs = new ArrayList<CountDrug>();
//					List<CountDrug> countDrugList = this.ordersService.countByDrug(wardCode, "", storageId, UserUtils.getOrgId());
//					for (CountDrug countDrug : countDrugList) {
//						double amount = this.countAmount(countDrug.getClinicItemId(), dispOrderDetails);
//						if (amount <= 0) {
//							continue;
//						}
//						countDrug.setAmount(amount);
//						countDrug.setDays(orders.getDays());
//						countDrugs.add(countDrug);
//					}
//					model.addAttribute("countDrugList", countDrugs);
//				} else {
//					throw new IllegalArgumentException("中间表数据保存失败");
//				}
//			}
//		}
//		model.addAttribute("storageDepts", this.drugStorageDeptService.findList(new DrugStorageDept()));
//		return "modules/nurse/preSetMedic";
//	}

//	/**
//	 *护理端-预摆药查询打印
//	 * @param orders
//	 * @return
//	 * @auhtor
//	 */
//	@RequiresPermissions("user")
//	@RequestMapping(value = {"dispIndexPrint", ""})
//	@ResponseBody
//	public StringData dispIndexPrint(Orders orders) throws ParseException {
//		StringData stringData = new StringData();
//		String printPath=ordersService.dispIndexPrint(orders);
//		stringData.setCode("success");
//		stringData.setData(printPath);
//		return stringData;
//	}

	/**
	 * 统计某个药品摆药总数
	 * @param clinicItemId
	 * @param dispOrderDetails
	 * @return
	 * @author  赵宁
	 */
	private double countAmount(String clinicItemId, List<Orders> dispOrderDetails) {
		double amount = 0;
		for (Orders order : dispOrderDetails) {
			String cId = order.getClinicItemId();
			if (clinicItemId.equals(cId)) {
				amount += order.getAmount();
			}
		}
		return amount;
	}
	/**
	 * 遗嘱摆药--摆药详情页面
	 * @return
	 * @author  赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"dispOrderDetails", ""})
	public String dispOrderDetails(Orders orders, HttpServletRequest request, HttpServletResponse response, Model model) {
		model.addAttribute("ordersList", request.getSession().getAttribute("dispOrderDetails"));
		return "modules/nurse/preSetMedicRight";
	}

	/**
	 * 查询摆药（药品信息）
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 * @author  赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"prescDurgClass", ""})
	public String prescDurgClass(Model model,DrugDispRec drugDispRec,HttpServletRequest request,HttpServletResponse response ){
		String wardCode = UserUtils.getUser().getOrgDept().getId();
		if(wardCode!=null){
			drugDispRec.setWardCode(wardCode);
		}
		if(drugDispRec.getStartTime()==null || "".equals(drugDispRec.getStartTime())){
			drugDispRec.setStartTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		if(drugDispRec.getEndTime()==null || "".equals(drugDispRec.getEndTime())){
			drugDispRec.setEndTime(DateUtils.getDate("yyyy-MM-dd"));
		}
        Page<DrugDispRec> page=drugDispRecService.findDrugPage(new Page<DrugDispRec>(request,response),drugDispRec);
		model.addAttribute("page",page);
		model.addAttribute("drugDispRec",drugDispRec);
		return "modules/nurse/prescDrugClass";
	}
	/**
	 * 护士端--摆药查询（药品）打印
	 * @param drugDispRec
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"prescDurgClassPrint", ""})
	@ResponseBody
	public StringData prescDurgClassPrint(DrugDispRec drugDispRec ){
		StringData stringData = new StringData();
		String printPath=drugDispRecService.prescDurgClassPrint(drugDispRec);
		stringData.setData(printPath);
		stringData.setCode("success");
		return stringData;
	}


	/**
	 * 摆药查询（个人）
	 * @param model
	 * @param drugDispRec
	 * @param request
	 * @param response
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"prescPatDrug", ""})
	public String prescPatDrug(Model model,DrugDispRec drugDispRec, String type,HttpServletRequest request,HttpServletResponse response){
		String wardCode = UserUtils.getUser().getOrgDept().getId();
		if(wardCode!=null){
            drugDispRec.setWardCode(wardCode);
		}
		if(drugDispRec.getStartTime()==null || "".equals(drugDispRec.getStartTime())){
			drugDispRec.setStartTime(DateUtils.getDate("yyyy-MM-dd"));
		}
		if(drugDispRec.getEndTime()==null || "".equals(drugDispRec.getEndTime())){
			drugDispRec.setEndTime(DateUtils.getDate("yyyy-MM-dd"));
		}
        Page<DrugDispRec> page=drugDispRecService.findDrugPatPage(new Page<DrugDispRec>(request,response),drugDispRec);
		model.addAttribute("page",page);
		model.addAttribute("drugDispRec",drugDispRec);
        if(StringUtils.isNotBlank(type)&&type.equals("1")){
            return "modules/nurse/prescPatDrugClass";
        }else{
            return "modules/nurse/prescDrugClass";
        }
	}

	/**
	 * 摆药查询（个人）-打印
	 * @param drugDispRec
	 * @return
	 * @author CTQ
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"prescPatDrugPrint", ""})
	@ResponseBody
	public StringData prescPatDrugPrint(DrugDispRec drugDispRec){
		StringData stringData = new StringData();
		String printPath=drugDispRecService.prescPatDrugPrint(drugDispRec);
		stringData.setData(printPath);
		stringData.setCode("success");
		return stringData;
	}
	/**
	 * 出院未尽项目页面加载
	 * @return
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"unFinishedItems", ""})
	public String unFinishedItems(String visitNo,String bedNo,PatVisit patVisit ,Model model){
		patVisit.setWardCode(UserUtils.getUser().getOrgDept().getId());
		if(visitNo!=null && visitNo!=""){
			patVisit.setVisitNo(visitNo);
			patVisit=patVisitService.getPatInfo(patVisit);
		}
		if(bedNo!=null && bedNo!=""){
			patVisit.setBedNo(bedNo);
			patVisit=patVisitService.getPatInfo(patVisit);
		}
		model.addAttribute("patVisit",patVisit);
		return "modules/nurse/outHosUnfinished";
	}

	/**
	 * 出院未尽项目查询(检查，检验，处方)
	 * @param model
	 * @param patVisit
	 * @return
	 * @author 赵宁
	 */
	@RequiresPermissions("user")
	@RequestMapping(value = {"outHosUnfinished", ""})
	public String outHosUnfinished(Model model,PatVisit patVisit, String id,String type){
		String pageUrl="";
		patVisit.setWardCode(UserUtils.getUser().getOrgDept().getId());
		if(patVisit.getBedNo()!=null && patVisit.getBedNo()!="" || patVisit.getVisitNo()!=null && patVisit.getVisitNo()!=""){
			patVisit=patVisitService.getPatInfo(patVisit);

		}
		model.addAttribute("patVisit",patVisit);
		List<PrescriptionApply> prescriptionApplies=new ArrayList<PrescriptionApply>();
		List<ExamApply> examApplies=new ArrayList<ExamApply>();
		List<LabApply> labApplies=new ArrayList<LabApply>();
        patVisit.setId(id);
			if(type==null || type=="undefined" || type.equals("exam") ){
				if(patVisit!=null && patVisit.getId()!=null){
					examApplies=examApplyService.getUnfinished(patVisit.getId());
				}
				model.addAttribute("examApplies",examApplies);
				pageUrl="modules/nurse/unFinishedExam";
			}else if(type.equals("lab")){
				if(patVisit!=null && patVisit.getId()!=null){
					labApplies=labApplyService.getUnfinishedLab(patVisit.getId());
				}
				model.addAttribute("labApplies",labApplies);
				pageUrl= "modules/nurse/unFinishedLab";
			}else if(type.equals("presc")){
				if(patVisit!=null && patVisit.getId()!=null){
					prescriptionApplies =prescriptionApplyService.prescInfoUnfinished(patVisit.getId());
				}
				model.addAttribute("prescriptionApplies",prescriptionApplies);
				pageUrl="modules/nurse/unFinishedPresc";
			}

		return pageUrl;
	}

}